﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;


namespace MapContentExtension
{
    /// <summary>
    /// Klasse zum Speichern von Kartendaten.
    /// </summary>
    [ContentTypeWriter]
    class MapDataWriter : ContentTypeWriter<MapData>
    {
        /// <summary>
        /// Schreibt Kartendaten
        /// </summary>
        /// <param name="output">Der Ausgabestrom</param>
        /// <param name="mapData">Die zu schreibende Karte</param>
        protected override void Write(ContentWriter output, MapData mapData)
        {
            // schreibe die Kartenausmaße
            output.Write(mapData.Width);
            output.Write(mapData.Height);

            // schreibe den Dateinamen des verwendeten Tilesets
            output.Write(mapData.Tileset);

            // schreibe die Anzahl der Ebenen
            output.Write(mapData.Data.Length);

            // schreibe die Namen der Layer
            foreach (string key in mapData.NameToLayer.Keys)
            {
                output.Write(key);
            }

            // schreibe alle Layer
            for (int layer = 0; layer < mapData.Data.Length; layer++)
            {
                foreach (short i in mapData.Data[layer])
                {
                    output.Write(i);
                }
            }
        }
        public override string GetRuntimeType(TargetPlatform targetPlatform)
        {
            return typeof(MapData).AssemblyQualifiedName;
        }
        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return "BeachRunner.Tileengine.MapDataReader, BeachRunner," +
                " Version=1.0.0.0, Culture=neutral";
        }
    }
}